home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 6639 / 6639.xpi / chrome / easydragtogo.jar / content / utils.js < prev   
Text File  |  2008-05-08  |  2KB  |  61 lines

  1. // Code by Sunwan
  2. //
  3.  
  4. var easyDragUtils = {
  5.  
  6.     pref:           Components.classes['@mozilla.org/preferences-service;1'].
  7.                       getService(Components.interfaces.nsIPrefService).getBranch("extensions.easydragtogo."),
  8.     WinDlFolder:    '\\My Documents\\My Pictures',
  9.     MacDlFolder:    '/Pictures',
  10.     UnixDlFolder:   '/Desktop',
  11.  
  12.     _dlFolder: null,
  13.     get dlFolder() {
  14.       if (!this._dlFolder) {
  15.         var fileLocator = Components.classes["@mozilla.org/file/directory_service;1"].
  16.                             getService(Components.interfaces.nsIProperties);
  17.         var dir = fileLocator.get("Home", Components.interfaces.nsILocalFile);
  18.         var platform = navigator.platform;
  19.         if (platform.indexOf("Win") == 0)
  20.           this._dlFolder = dir.path + this.WinDlFolder;
  21.         else if (platform.indexOf("Mac") == 0)
  22.           this._dlFolder = dir.path + this.MacDlFolder;
  23.         else
  24.           this._dlFolder = dir.path + this.UnixDlFolder;
  25.       }
  26.       return this._dlFolder;
  27.     },
  28.  
  29.     getDownloadFolder: function() {
  30.       return this.getPref("img.folder", this.dlFolder);
  31.     },
  32.  
  33.     getPref: function(prefname, value) {
  34.       try {
  35.         var scelta;
  36.         if (typeof(value) == "boolean")
  37.           scelta = this.pref.getBoolPref(prefname);
  38.         else if (typeof(value) == "number")
  39.           scelta = this.pref.getIntPref(prefname);
  40.         else if (typeof(value) == "string")
  41.           scelta = this.pref.getComplexValue(prefname, Components.interfaces.nsISupportsString).data;
  42.         return scelta;
  43.       } catch (e) {
  44.         this.setPref(prefname, value);
  45.         return value;
  46.       }
  47.     },
  48.  
  49.     setPref: function(prefname, value) {
  50.       if (typeof(value) == "boolean")
  51.         this.pref.setBoolPref(prefname, value);
  52.       else if (typeof(value) == "number")
  53.         this.pref.setIntPref(prefname, value);
  54.       else if (typeof(value) == "string") {
  55.         var str = Components.classes["@mozilla.org/supports-string;1"].
  56.                     createInstance(Components.interfaces.nsISupportsString);
  57.         str.data = value;
  58.         this.pref.setComplexValue(prefname, Components.interfaces.nsISupportsString, str);
  59.       }
  60.     }
  61. };